package com.jy.importclient.support;

import com.jy.importclient.handler.ScheduledRetrySubtaskHandler;
import com.jy.importclient.handler.ScheduledTaskHandler;
import com.jy.importclient.properties.FixTimeTaskProperties;
import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @类名 QuartzSupport
 * @描述 TODO
 * @作者 白条君
 * @创建日期 2023/7/7 10:50
 * @版本 1.0
 */
@Component
public class QuartzSupport {

    @Resource
    private FixTimeTaskProperties properties;

    public void generateSimpleScheduledTask(Class<? extends Job> clazz, String identity, String group) throws SchedulerException {
        Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();

        JobDetail jobDetail = JobBuilder.newJob(clazz).withIdentity(identity).build();

        SimpleScheduleBuilder simpleScheduleBuilder = SimpleScheduleBuilder.simpleSchedule().withIntervalInSeconds(properties.getInterval()).repeatForever();
        SimpleTrigger simpleTrigger = TriggerBuilder.newTrigger().withIdentity(group).withSchedule(simpleScheduleBuilder).build();

        scheduler.scheduleJob(jobDetail, simpleTrigger);
        scheduler.startDelayed(3);
        scheduler.start();
    }
}
